/*
 * @Author: 薛严 348352046@qq.com
 * @Date: 2022-11-12 19:01:35
 * @LastEditors: ayun chengyunwu@jiatui.com
 * @LastEditTime: 2023-05-11 13:41:44
 * @FilePath: /gov-baoan-h5/vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import {
  createStyleImportPlugin,
  AndDesignVueResolve,
  VantResolve,
  ElementPlusResolve,
  NutuiResolve,
  AntdResolve,
} from 'vite-plugin-style-import' // 按需加载
import { createHtmlPlugin } from 'vite-plugin-html' //
import tsChecker from 'vite-plugin-checker' // ts检查
// const postcssPresetEnv = require ('postcss-preset-env');
// https://vitejs.dev/config/

export default defineConfig(({ command, mode }) => {
  const root = process.cwd()
  const env = loadEnv(process.argv[process.argv.length - 1], root)
  return {
    base: './',
    server: {
      proxy: {
        '/api': {
          target: 'http://10.190.219.5:8090/',
          changeOrigin: true,
          cors:true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
    build: {
      // outDir: `dist-${mode}`,
      outDir: 'dist',
      rollupOptions: {
        output: {
          assetFileNames: '[hash].[name].[ext]',
        },
      },
      terserOptions: {
        compress: {
          drop_console: false,
          drop_debugger: false,
        },
      },
      assetsInlineLimit: 4096,
      // assetsDir:'static' // 资源别名
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `
          @import '@/assets/styles/index.scss';
          $VITE_IMAGEBASE:'${env.VITE_IMAGEBASE}';`,
        },
      },
      devSourcemap: true,
      postcss: {
        plugins: [
          //  postcssPresetEnv()
        ],
      },
    },
    plugins: [
      react(),
      createHtmlPlugin({
        inject: {
          data: {
            title: '福田经济运行一网统管信息系统',
          },
        },
      }),
      createStyleImportPlugin({
        resolves: [
          AndDesignVueResolve(),
          VantResolve(),
          ElementPlusResolve(),
          NutuiResolve(),
          AntdResolve(),
        ],
        libs: [
          // If you don’t have the resolve you need, you can write it directly in the lib, or you can provide us with PR
          // {
          //   libraryName: 'antd-mobile',
          //   esModule: true,
          //   resolveStyle: (name) => {
          //     return `antd-mobile/es/components/${name}/${name}.css`
          //   },
          // },
        ],
      }),
      tsChecker({
        typescript: true,
      }),
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
        '@assets': path.resolve(__dirname, './src/assets'),
      },
    },
  }
})
